
const express = require('express')
const router = express.Router()

// 获取采购订单列表
router.get('/orders', (req, res) => {
  const orders = [
    {
      id: 'PO20241101001',
      type: '总部集中采购',
      supplier: '优质农产品供应商A',
      items: [
        { name: '有机蔬菜', quantity: 1000, unit: 'kg' },
        { name: '精品水果', quantity: 500, unit: 'kg' }
      ],
      status: '已确认',
      createdAt: '2024-11-01 08:00:00'
    },
    {
      id: 'PO20241101002',
      type: '区域柔性采购',
      supplier: '本地农场B',
      items: [
        { name: '新鲜牛奶', quantity: 200, unit: 'L' },
        { name: '草鸡蛋', quantity: 300, unit: '盒' }
      ],
      status: '运输中',
      createdAt: '2024-11-01 09:30:00'
    }
  ]
  res.json(orders)
})

// 创建采购订单
router.post('/orders', (req, res) => {
  const { type, supplier, items } = req.body
  const order = {
    id: `PO${Date.now()}`,
    type,
    supplier,
    items,
    status: '待确认',
    createdAt: new Date().toLocaleString('zh-CN')
  }
  res.json({ success: true, order })
})

module.exports = router
